package cn.edu.usst.cs.goldfish.booking.meetingroom.mapstruct;

import cn.edu.usst.cs.goldfish.booking.meetingroom.model.SysUser;
import cn.edu.usst.cs.goldfish.booking.meetingroom.web.dto.auth.RegisterRequest;
import cn.edu.usst.cs.goldfish.booking.meetingroom.web.dto.auth.UserPreview;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.stereotype.Component;

@Mapper(componentModel = "spring")
@Component
public interface AuthMapper {
    @Mappings(
            {
                    @Mapping(target = "id", ignore = true),
                    @Mapping(target = "balance", expression = "java(java.math.BigDecimal.ZERO)"),
                    @Mapping(target = "createdAt", expression = "java(java.time.LocalDateTime.now())"),
                    @Mapping(target = "updatedAt", expression = "java(java.time.LocalDateTime.now())")
            }
    )
    SysUser registerRequestToUser(UserPreview userPreview);

    @Mappings({})
    UserPreview toUserInfoPreview(RegisterRequest registerRequest);

    @Mappings({})
    UserPreview toUserInfoPreview(SysUser user);

    default SysUser registerRequestToUser(RegisterRequest registerRequest) {
        return registerRequestToUser(toUserInfoPreview(registerRequest));
    }
}
